﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SQLEditor.admin.entity;
using SQLEditor.admin.service;

namespace SQLEditor.admin.ashx
{
    /// <summary>
    /// rm_sqloperate 的摘要说明
    /// </summary>
    public class rm_sqlexercise : rm_base
    {
        SqlExerciseService service = new SqlExerciseService();
        public override void getall(HttpContext context)
        {
            UserEntity u = UserService.GetUser(context);
            string json = service.listQuestion(u.id);
            context.Response.Write(json);
        }

        public override void other(HttpContext context)
        {
            string action = context.Request.Params["action"];
            if ("answer" == action) {
                UserEntity u = UserService.GetUser(context);
                string questionId = context.Request.Params["questionId"];
                string answer = context.Request.Params["answer"].Trim();
                SqlAnswer result = service.answer(u.id, int.Parse(questionId), answer);
                string json = JsonUtil.ToJson(result);
                json = JsonUtil.ToJson(new { success = true, msg = json });
                context.Response.Write(json);
            }
            else if ("getProject" == action)
            {
                string projectId = context.Request.Params["projectId"];
                string remark = service.getProjectRemark(int.Parse(projectId));
                context.Response.Write(remark);
            }
            else if ("test" == action)
            {
                string json = service.test();
                context.Response.Write(json);
            }
        }
    }
}